<template>
  <div>
    <mu-dialog :open="show" title>
      <span class="t2">{{familyPerson.realname}}</span> 尚未进行身份认证，请先完成身份认证。
      <mu-flat-button slot="actions" @click="clickHandle" label="我知道了" />
      <mu-flat-button slot="actions" @click="confirmHandle" primary label="去认证" />
    </mu-dialog>
    <mu-dialog :open="dialogGenerate">
      <div v-if="isCreateOnline">
        <div class="center">
          <p>未查询到患者档案，是否在线建档？</p>
        </div>
        <div class="login center mt20">
          <mu-flat-button slot="actions" @click="dialogGenerate=false" label="否" />
          <mu-flat-button slot="actions" primary @click="createHandle" label="是" />
        </div>
      </div>
      <div v-else>
        <div class="center">
          <p>未查询到就诊人档案，请到医院窗口建档</p>
        </div>
        <div class="login center mt20">
          <mu-flat-button primary slot="actions" @click="dialogGenerate=false" label="我知道了" />
        </div>
      </div>
    </mu-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hospitalCode: sessionStorage.getItem("hospitalCode") || "1",
      dialogGenerate: false,
      isCreateOnline: false,
      form: {
        confirmType: "1",
        mobile: "",
        cardnum: "",
        receiveCode: ""
      },
      vcodeLabel: "获取验证码",
      vcodeDisabled: false
    };
  },
  props: ["familyPerson", "person", "show"],
  mounted() {
    this.getSysParameterList();
  },
  methods: {
    clickHandle() {
      this.$emit("update:show", false);
    },
    confirmHandle() {
      sessionStorage.editFamily = JSON.stringify(this.familyPerson);
      this.getHisPhone().then(res => {
        if (res.data.code == 200) {
          if (res.data.data && res.data.data.length > 0) {
            this.$router.replace({
              path: "/setting/bind-visitcard",
              query: { redirect: this.$route.path }
            });
          } else {
            this.dialogGenerate = true;
          }
        }
      });
    },
    createHandle() {
      this.$router.push({
        path: "/setting/createOnline"
      });
    },
    getHisPhone(operationType) {
      let q = JSON.parse(
        sessionStorage.editFamily || "{listBasAccountCard: []}"
      );
      const params = {
        hospitalCode: this.hospitalCode,
        operationType: operationType || "1"
      };
      if (q.relation > 0) {
        params.fid = q.id;
      }
      return this.$postJson(this.$API.getHisPhone, params, true);
    },
    /**
     * 获取系统参数
     */
    getSysParameterList() {
      let params = {
        moduleId: "000000",
        parameterKey: "ol_archivable"
      };
      this.$postJson(this.$API.getSysParameterList, params, true).then(res => {
        this.isCreateOnline = res.data.data[0].parameterValue == 1;
      });
    }
  }
};
</script>

